// rcli csv -i input.csv -o output.json --header -d ','

use clap::Parser;
use rcli::{
    base64_decode, base64_encode, handle_csv, process_gen_pass, Base64Command, Opts, SubCommand,
};

fn main() -> anyhow::Result<()> {
    let opts = Opts::parse();

    match opts.cmd {
        SubCommand::Csv(opts) => {
            let result = handle_csv(opts);
            match result {
                Ok(_) => println!("CSV to JSON conversion successful!!!"),
                Err(e) => eprintln!("Error: {}", e),
            }
        }
        SubCommand::GenPass(gen_pass_opts) => {
            let pass = process_gen_pass(
                gen_pass_opts.length,
                gen_pass_opts.uppercase,
                gen_pass_opts.lowercase,
                gen_pass_opts.number,
                gen_pass_opts.symbol,
            );
            match pass {
                Ok(password) => println!("Generated password: {}", password),
                Err(e) => eprintln!("Error: {}", e),
            }
        }
        SubCommand::Base64(base64_command) => match base64_command {
            Base64Command::Encode(opts) => {
                println!("*********** Base64 encode: {} ***********", &opts.input);
                let result = base64_encode(&opts.input, &opts.format);
                match result {
                    Ok(encoded) => println!("Encoded: {}", encoded),
                    Err(e) => eprintln!("Error: {}", e),
                }
            }
            Base64Command::Decode(opts) => {
                println!("*********** Base64 decode: {} ***********", &opts.input);
                let result = base64_decode(&opts.input, &opts.format);
                match result {
                    Ok(decoded) => println!("Decoded: {}", decoded),
                    Err(e) => eprintln!("Error: {}", e),
                }
            }
        },
    }

    Ok(())
}
